package nsh.cl.nd.khtn.mazedash;

import nsh.cl.nd.khtn.mazedash.game.play.GameMode;
import android.content.Context;
import android.content.SharedPreferences;
import android.widget.Toast;

public class PrefService {
	public static final String PREFS_NAME = "TapTapPrefs";
	public static final String PREF_KEY_BESTSCORE = "-bestScore";

	public static int getBestScore(GameMode gameMode) {
		return RootGameActivity.getInstance().getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
				.getInt(gameMode + PREF_KEY_BESTSCORE, Toast.LENGTH_SHORT);
	}

	public static void setBestScore(GameMode gameMode, int value) {
		setValue(gameMode + PREF_KEY_BESTSCORE, value);
	}

	private static void setValue(String key, Object value) {
		SharedPreferences.Editor editor = RootGameActivity.getInstance()
				.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE).edit();
		if (value instanceof Boolean) {
			editor.putBoolean(key, (Boolean) value);
		} else if (value instanceof Integer) {
			editor.putInt(key, (Integer) value);
		} else {
			editor.putString(key, value.toString());
		}

		editor.commit();
	}
}
